package com.lzh.controller;


import com.lzh.bean.SupplierInquiry;
import com.lzh.common.bean.PageBean;
import com.lzh.common.bean.ResultBean;
import com.lzh.common.controller.BaseController;
import com.lzh.domian.AjaxResult;
import com.lzh.query.SupplierInquiryQuery;
import com.lzh.service.SupplierInquiryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api( tags = "供应商询价单")
@RestController
@RequestMapping("/api")
public class SupplierInquiryController extends BaseController {

    @Autowired
    private SupplierInquiryService supplierInquiryService;

    /**
     * 查询供应商询价单
     * @param supplierInquiryQuery
     * @return
     */
    @ApiOperation("查询供应商询价单")
    @PutMapping("/supplierInquiry/list")
    public ResultBean querySupplierInquiry(@RequestBody SupplierInquiryQuery supplierInquiryQuery) {
        PageBean query = supplierInquiryService.query(supplierInquiryQuery);
        return new ResultBean(200,"查询供应商询价单",query);
    }


    /**
     * 保存供应商询价单
     * @param supplierInquiry
     * @return
     */
    @ApiOperation("保存供应商询价单")
    @PostMapping("/supplierInquiry")
    public AjaxResult saveSupplierInquiry(@RequestBody SupplierInquiry supplierInquiry){
        int save = supplierInquiryService.save(supplierInquiry);
        String tmp = save >0 ? "保存成功":"保存失败";
        return AjaxResult.success("保存供应商询价单",tmp);
    }

    /**
     * 查询根据id
     * @param id
     * @return
     */
    @ApiOperation("根据id查询供应商询价单id")
    @GetMapping("/supplierInquiry/{id}")
    public AjaxResult querySupplierInquiryById(@PathVariable("id") int id){
        SupplierInquiry supplierInquiry = supplierInquiryService.queryById(id);
        return AjaxResult.success("查询供应商询价单和详情",supplierInquiry);
    }
}
